//
//  ByForgetVC.m
//  jinpuyiyuan_ios
//
//  Created by pro on 2017/12/8.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByForgetVC.h"

// view
#import "ByViewUserOperateCustom.h"

@interface ByForgetVC ()
@property (nonatomic, strong) ByViewUserOperateCustom *userView;
@property (nonatomic, copy) NSArray *infoAry;
@end

@implementation ByForgetVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addLeftBackBarButtonItem];
    [self createViews];
    self.title = @"找回密码";
    self.view.backgroundColor = BY_THEME_COLOR;
}

#pragma mark - getter
- (NSArray *)infoAry{
    if (!_infoAry) {
        _infoAry = @[@[@"手机号码",@"验证码",@"重置密码",@"验证码"],@[@"",@"",@"8-24位密码",@"请再次输入登录密码"]];
    }
    return _infoAry;
}

#pragma mark - create views
- (void)createViews{
    self.userView = [[ByViewUserOperateCustom alloc] init];
    [self.view addSubview:self.userView];
    NSArray *titles = self.infoAry[0];
    [self.userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(15));
        if (@available(iOS 11.0,*)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(20);
        }else{
            make.top.equalTo(self.view.mas_top).offset(20);
        }
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 30, titles.count * 30 + 100 + 20 * (titles.count - 1)));
    }];
    self.userView.infoAry = self.infoAry;
    [self.view addSubview:self.userView];
    
    UIButton *sureButton = [[UIButton alloc] init];
    [self.view addSubview:sureButton];
    CGFloat width = [@"确认" getSizeOfString:14].width + 80;
    [sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@((SCREEN_WIDTH - width) / 2));
        make.top.equalTo(self.userView.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake(width, 40));
    }];
    sureButton.backgroundColor = [UIColor whiteColor];
    [sureButton setTitleColor:BY_THEME_COLOR forState:UIControlStateNormal];
    [sureButton setTitle:@"确认" forState:UIControlStateNormal];
    sureButton.titleLabel.font = FONT(14);
    sureButton.layer.cornerRadius = 4.0;
    [sureButton addTarget:self action:@selector(sureAction) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark - 确认
- (void)sureAction{
    UITextField *nameTf = [self.userView viewWithTag:10];
    UITextField *codeTf = [self.userView viewWithTag:11];
    UITextField *passTf = [self.userView viewWithTag:12];
    UITextField *conTf = [self.userView viewWithTag:13];
    if (nameTf.text.length == 0) {
        [ByCoreToolAlert showOnlyText:@"请输入手机号"];
        return;
    }
    if (codeTf.text.length == 0) {
        [ByCoreToolAlert showOnlyText:@"请输入验证码"];
        return;
    }
    if (passTf.text.length == 0) {
        [ByCoreToolAlert showOnlyText:@"请输入密码"];
        return;
    }
    
    if (conTf.text.length == 0) {
        [ByCoreToolAlert showOnlyText:@"请再次确认密码"];
        return;
    }
    
    if (passTf.text.length < 8  || passTf.text.length > 24) {
        [ByCoreToolAlert showOnlyText:@"密码长度为8-24位"];
        return;
    }
    
    if (![passTf.text isEqualToString:conTf.text]) {
        [ByCoreToolAlert showOnlyText:@"两次输入密码不一致"];
        return;
    }
   
}
@end
